<template>
  <div class="weather_box">
    <h3 class="h3">天气预报</h3>
    <div class="weatherheader">
      <el-select placeholder="Select" v-model="value" @change="handleChange">
        <el-option
          v-for="item in cityList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
          :disabled="item.disabled"
        />
      </el-select>
      <el-button @click="confirmWeather">确定</el-button>
    </div>
    <div>
      <div>
        <div class="weatherCity">{{ detaileWeather.city }}</div>
        <div class="weather_img" v-if="flag == '多云'">
          <img src="../assets/img/天气.png" alt="" />{{ detaileWeather.wea }}
          <span>{{ detaileWeather.tem2 }}°-{{ detaileWeather.tem1 }}°</span>
        </div>
        <div class="weather_img" v-if="flag == '雾'">
          <img src="../assets/img/wu.png" alt="" />{{ detaileWeather.wea }}
          <span>{{ detaileWeather.tem2 }}°-{{ detaileWeather.tem1 }}°</span>
        </div>
        <div class="weather_img" v-if="flag == '霾'">
          <img src="../assets/img/雾霾.png" alt="" />{{ detaileWeather.wea }}
          <span>{{ detaileWeather.tem2 }}°-{{ detaileWeather.tem1 }}°</span>
        </div>
        <div class="weather_img" v-if="flag == '晴'">
          <img src="../assets/img/晴.png" alt="" />{{ detaileWeather.wea }}
          <span>{{ detaileWeather.tem2 }}°-{{ detaileWeather.tem1 }}°</span>
        </div>
        <div class="weather_img" v-if="flag == '阴'">
          <img src="../assets/img/天气-阴天.png" alt="" />{{ detaileWeather.wea
          }}<span>{{ detaileWeather.tem2 }}°-{{ detaileWeather.tem1 }}°</span>
        </div>
        <div>
          <p>当前温度 {{ detaileWeather.tem }}°</p>
        </div>
        <p class="introduction">{{ detaileWeather.air_tips }}</p>
      </div>
    </div>
  </div>
</template>
<script>
import { formatDate } from "../util/tool";
import { getw } from "../api/serve";
export default {
  name: "tag",
  data() {
    return {
      cityList: [
        {
          value: "运城",
          label: "运城",
        },
        {
          value: "大同",
          label: "大同",
        },
        {
          value: "临汾",
          label: "临汾",
        },
        {
          value: "吕梁",
          label: "吕梁",
        },
        {
          value: "巴中",
          label: "巴中",
        },
        {
          value: "白城",
          label: "白城",
        },
      ],
      value: "运城",
      detaileWeather: "",
      flag: "",
    };
  },
  watch: {},
  mounted() {
    this.init(this.value);
  },
  methods: {
    handleChange(value) {
      this.value = value;
      console.log(this.value);
    },
    init(value) {
      getw({ city: value }, (res) => {
        this.detaileWeather = res;
        this.flag = res.wea;
      });
    },
    confirmWeather() {
      this.init(this.value);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.weather_box {
  color: rgb(95, 93, 93);
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
}
.introduction {
  margin-top: 10px;
}
.weatherCity {
  margin-bottom: 5px;
}
.weather_img img {
  width: 30px;
}
.weather_img {
  display: flex;
  align-items: center;
  img {
    margin-right: 10px;
  }
  span {
    margin-left: 5px;
  }
  margin-bottom: 12px;
}
.weatherheader::after {
  display: block;
  content: "";
  height: 2px;
  background: rgb(231, 226, 226);
  margin-top: 15px;
  margin-bottom: 15px;
}
.weatherheader {
  text-align: center;
}
.weather_box:hover .h3::after {
  width: 100%;
}
.weather_box {
  padding: 15px;
  background: #fff;
  margin-top: 20px;
  .el-button {
    border-radius: 0 !important;
    // height: 15px;
  }
  & h3::after {
    content: "";
    display: block;
    margin-top: 20px;
    width: 60px;
    height: 4px;
    border-radius: 20px;
    background-color: rgb(51, 51, 51);
    transition: width 0.3s ease;
    margin-bottom: 15px;
  }
}
</style>
